package com.mrx.spring.example.runner;

import com.mrx.commons.trace.TraceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author Mr.X
 * @since 2023-11-10 16:26
 **/
@Component
public class TraceIdRunner {

    private static final Logger logger = LoggerFactory.getLogger(TraceIdRunner.class);

    @Resource
    private RedisTemplate<String, String> redisTemplate;

    @PostConstruct
    public void init() {
        logger.debug("traceId: {}, 构造 TraceIdRunner", TraceUtils.getTraceId());
    }

    @Async("traceExecutor")
    @EventListener(ApplicationReadyEvent.class)
    public void init(ApplicationReadyEvent ignore) {
        logger.info("traceId: {}, Spring 容器启动完毕", TraceUtils.getTraceId());
    }

}
